/*
 * @(#)ChainFilter.java
 * Date 2013-09-30
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.model;

import java.util.ArrayList;
import java.util.List;


/**
 * Class description
 *
 *
 * @param <T>
 *
 * @version        v1.0, 2013-09-30
 * @author         Jim Horner
 */
public class ChainFilter<T> implements IFilter<T> {

    /** Field description */
    public final List<IFilter<T>> filters;

    /**
     * Constructs ...
     *
     *
     */
    public ChainFilter() {

        super();
        this.filters = new ArrayList<>();
    }

    /**
     * Method description
     *
     *
     * @param item
     *
     * @return
     */
    @Override
    public boolean accept(T item) {

        boolean result = true;

        for (IFilter<T> filter : this.filters) {

            if (filter.accept(item) == false) {

                result = false;

                break;
            }
        }

        return result;
    }

    /**
     * Method description
     *
     *
     * @param filter
     */
    public void add(IFilter<T> filter) {

        this.filters.add(filter);
    }
}
